// JavaScript Document
$(document).ready(function() {
	$('a.login-window').click(function() {
		
		// Getting the variable's value from a link 
		var loginBox = $(this).attr('href');

		//Fade in the Popup and add close button
		$(loginBox).fadeIn(300);
		
		//Set the center alignment padding + border
		var popMargTop = ($(loginBox).height() + 24) / 2; 
		var popMargLeft = ($(loginBox).width() + 24) / 2; 
		
		$(loginBox).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		// Add the mask to body
		$('body').append('<div id="mask"></div>');
		$('#mask').fadeIn(300);
		
		return false;
	});
	
	// When clicking on the button close or the mask layer the popup closed
	$('a.close, #mask').live('click', function() { 
	  $('#mask , .login-popup').fadeOut(300 , function() {
		$('#mask').remove();  
	}); 
	return false;
	});
});

window.onload = function(){
 var countArr = [];
 var obj = getClass(document.body,"box");
 for(var i=0;i<obj.length;i++){
  for( var j=0;j<obj[i].getElementsByTagName("li").length;j++){
   var liObj = obj[i].getElementsByTagName("li")[j];
   countArr.push(liObj);
   liObj.onmouseover = function(){
    for(var k=0;k<countArr.length;k++){
     startMove(countArr[k],{opacity:30});
    }
    startMove(this,{opacity:100});
   }
   liObj.onmouseout = function(){
    for(var k=0;k<countArr.length;k++){
     startMove(countArr[k],{opacity:100});
    }
   }
  }
 }
}
/**
* 通过class获取对象
*/
function getClass(oParent, sClass){
 var aElem = oParent.getElementsByTagName('*');
 var aClass = [];
 var i = 0;
 for(i=0;i<aElem.length;i++)if(aElem[i].className == sClass)aClass.push(aElem[i]);
 return aClass;
}
/**
* 动作类
* 用法：
* startMove(目标对象 ,目标属性(多个), 动作完成后执行(fun))
*/
function startMove(target, object, onComplete){
 if(target.timer)clearInterval(target.timer);
 target.timer = setInterval(function (){
  doMove(target, object, onComplete);
 }, 30);
}
function getStyle(target, attr){
 return target.currentStyle?target.currentStyle[attr]:getComputedStyle(target, false)[attr];
}
function doMove(target, object, onComplete){
 var iCur = 0;
 var attr = '';
 var bStop = true;
 for(attr in object){
  attr == 'opacity' ? iCur = parseInt(parseFloat(getStyle(target, 'opacity'))*100) : iCur = parseInt(getStyle(target, attr));
  if(isNaN(iCur))iCur = 0;
  if(navigator.userAgent.indexOf("Firefox") > 0){
   var iSpeed = (object[attr]-iCur) / 3;
  }else{
   var iSpeed = (object[attr]-iCur) / 3;
  }
  iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
  if(parseInt(object[attr])!=iCur)bStop = false;
  if(attr=='opacity'){
   target.style.filter = "alpha(opacity:"+(iCur+iSpeed)+")";
   target.style.opacity = (iCur + iSpeed) / 100;
  }else{
   attr == 'zIndex' ? target.style[attr] = iCur + iSpeed : target.style[attr] = iCur + iSpeed +'px';
  }
 }
 if(bStop){
  clearInterval(target.timer);
  target.timer = null;  
  if(onComplete)onComplete();
 }
}
$(function(){
$(".box li").each(function() {
  $(this).hover(function() {
   $(this).find('.txtDesc').slideDown(200);
   if(!$(this).hasClass('hover'))
   {
    $(this).addClass("hover");
   }
 },
  function() {
   $(this).find('.txtDesc').hide(); 
   if($(this).hasClass('hover'))
   {
    $(this).removeClass("hover");
   }  
  });
 });
})

